package com.scau.database.finalexam.config;



import com.scau.database.finalexam.component.LoginHandlerInterceptor;
import com.scau.database.finalexam.component.MyLocalResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class MyMvcConfig extends WebMvcConfigurationSupport {


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截所有 排除"/"
        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**")
                        .excludePathPatterns("/index.html","/","/user/login");

    }


    public void addViewControllers(ViewControllerRegistry registry) {
        //添加视图映射（如果只是请求跳转 不处理数据的话 没必要写RequestMapping了）
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/index.html").setViewName("login");
        registry.addViewController("/main.html").setViewName("dashboard");
//        registry.add
    }

    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocalResolver();
    }



}
